<?php

class Usuario extends Model {

	function __construct()
	{
		parent::Model();
	}
	
	function all() {
		return $this->getBySubprograma();
	}
	
	function getBySubprograma($subprograma_id){
		$this->db->select('u.*, i.nome as nome_instituicao, s.nome as nome_subprograma');
		$this->db->from('rel_usuario as u');
		$this->db->join('rel_instituicao as i', 'i.id = u.instituicao_id');
		$this->db->join('rel_subprograma as s', 's.id = u.subprograma_id', 'left');
		if($subprograma_id != '') 
			$this->db->where('s.id =', $subprograma_id);
		return $this->db->get()->result();
	}
	// --------------------------------------------------------------------

      /** 
       * function SaveForm()
       *
       * insert form data
       * @param $form_data - array
       * @return Bool - TRUE or FALSE
       */

	function save_form($form_data)
	{
		if($form_data["id"] == '') $this->db->insert('rel_usuario', $form_data);
		else $this->db->update('rel_usuario', $form_data, array('id' => $form_data["id"]));
		
		return TRUE;
	}
}
?>